#create you views here

#from django.http import HttpResponse

from django.shortcuts import render_to_response
from django.template.context import RequestContext
from python_residencia_rise.empresaApp.models import Empresa
from python_residencia_rise.empresaApp.forms import EmpresasForm
from django.http import HttpResponseRedirect
 

def listar_empresas(request):

    empresas = Empresa.objects.all()
    return render_to_response( 'listar_empresas.html', locals(), context_instance=RequestContext(request))
    
def nova_empresa(request):
    
    if request.method == 'POST':
        form = EmpresasForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('listar')
    else:
        form = EmpresasForm()
    return render_to_response('nova_empresa.html', locals(), context_instance=RequestContext(request))

    
